#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
    int x = 0,sgn = 1;char ch = getchar();
    for(;!isdigit(ch);ch=getchar())if(ch=='-')sgn=-1;
    for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
    return x*sgn;
}

const int N = 4e5+10;

int n,m,lst[N],deg[N],scc,bel[N],dfn[N],tim,low[N],stk[N],top,ndn;
int h[N],cnt;
bool vis[N];
struct edge {int v,nxt;}e[N<<2];
void link(int x,int y) {e[++cnt] = (edge){y,h[x]}; h[x] = cnt;}

void dfs(int x) {
	dfn[x] = low[x] = ++tim; stk[++top] = x; vis[x] = 1;
	for(int i = h[x],y;i;i = e[i].nxt)
		if(!dfn[y = e[i].v]) dfs(y),low[x] = min(low[x],low[y]);
		else if(vis[y]) low[x] = min(low[x],dfn[y]);
	if(low[x] == dfn[x]) {
		int y; ++scc;
		do {
			y = stk[top--]; bel[y] = scc; vis[y] = 0;
		}while(x ^ y);
	}
}

void solve() {
	n = in,m = in; ndn = 0; 
	vector<vector<char> > grid(n + 2,vector<char>(m + 2));
	vector<vector<int> > id(n + 2,vector<int>(m + 2));
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++) {
			grid[i][j] = getchar(); while(grid[i][j] != '#' && grid[i][j] != '.') grid[i][j] = getchar();
			if(grid[i][j] == '#') id[i][j] = ++ndn;
		}
	for(int i = n;i >= 1;i--) {
		for(int j = 1;j <= m;j++)
			if(grid[i][j] == '#') {
				if(id[i - 1][j]) link(id[i][j],id[i - 1][j]);
				if(lst[j]) link(id[i][j],lst[j]);
				if(id[i][j - 1]) link(id[i][j],id[i][j - 1]);
				else if(lst[j - 1]) link(id[i][j],lst[j - 1]);
				if(id[i][j + 1]) link(id[i][j],id[i][j + 1]);
				else if(lst[j + 1]) link(id[i][j],lst[j + 1]);
			}
		for(int j = 1;j <= m;j++) if(grid[i][j] == '#') lst[j] = id[i][j];
	}
	for(int i = 1;i <= ndn;i++) if(!dfn[i]) dfs(i);
	for(int i = 1;i <= ndn;i++)
		for(int j = h[i],y;j;j = e[j].nxt)
			if(bel[i] ^ bel[y = e[j].v]) deg[bel[y]]++;
	int cnt = 0;
	for(int i = 1;i <= scc;i++) if(deg[i] == 0) cnt++;
	cout << cnt << endl;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
    solve();
    return 0;
}
